package com.untour.im.client.handler;

import com.untour.im.client.command.ClientPacketEncodec;
import com.untour.im.client.message.ClientMessage;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToByteEncoder;

/**
 * 消息编码类
 **/
public class RequestMessageEncoderHandler extends MessageToByteEncoder<ClientMessage> {
    private final Integer clientType;
    public RequestMessageEncoderHandler(Integer clientType) {
        this.clientType = clientType;
    }

    @Override
    protected void encode(ChannelHandlerContext ctx, ClientMessage packet, ByteBuf out) throws Exception {
        packet.setClientType(clientType);
        ClientPacketEncodec.INSTANCE.encode(out,packet);
    }

}
